package module03.Question5;

import com.lagou.task10.Man;

import java.util.*;
import java.util.Random;

/**
 *  使用集合实现斗地主游戏的部分功能，要求如下：

         （1）首先准备 54 张扑克牌并打乱顺序。

         （2）由三个玩家交替摸牌，每人 17 张扑克牌，最后三张留作底牌。

         （3）查看三个玩家手中的扑克牌和底牌。

         （4）其中玩家手中的扑克牌需要按照大小顺序打印，规则如下：

         手中扑克牌从大到小的摆放顺序：大王,小王,2,A,K,Q,J,10,9,8,7,6,5,4,3*/



public class poker {

    public static void main(String[] args) {

        List<String> colorList = Arrays.asList("♠", "♥", "♣", "♦");//花色
        List<String> pointList = Arrays.asList("2", "A", "K", "Q", "J",
                "10", "9", "8", "7", "6", "5", "4", "3");//点数
        List<String> KingList = Arrays.asList("大王", "小王");//王牌

        Map<Integer, String> pokerMap = new HashMap<>();
        List<Integer> pokerList = new ArrayList<>();

        //将牌编号
        int num = 0;
        pokerList.add(num);
        pokerMap.put(num++, KingList.get(0));//大王
        pokerList.add(num);
        pokerMap.put(num++, KingList.get(1));//小王
        for (String point : pointList)
            for (String color : colorList) {
                pokerList.add(num);
                pokerMap.put(num++, color + " " + point);
            }//放入牌

        //记录玩家的牌
        List<Integer> player1 = new ArrayList<>();
        List<Integer> player2 = new ArrayList<>();
        List<Integer> player3 = new ArrayList<>();
        List<Integer> last = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            Integer int1 = pokerList.get(i);
            if (i >= 51){
                last.add(int1);
            } else if (0 == i%3) {
                player1.add(int1);
            } else if (1 == i%3) {
                player2.add(int1);
            } else {
                player3.add(int1);
            }
        }

        //排序
        Collections.sort(player1);
        Collections.sort(player2);
        Collections.sort(player3);
        Collections.sort(last);

        //显示手牌
        showPoker(1, player1, pokerMap);
        showPoker(2, player2, pokerMap);
        showPoker(3, player3, pokerMap);
        showPoker(4, last, pokerMap);

    }
    public static void  showPoker (int i, List<Integer> list, Map<Integer, String> pokerMap)   {
        System.out.println("展示手牌：");
        for (Integer int1 : list) {
            System.out.print(pokerMap.get(int1) + "");
        }
        System.out.println();
    }
}
